<template>
  <div class="siteHis">
    <eagle-page-list
      ref="eaglePageList"
      @bindData="bindData"
      :queryParams="queryParams"
      :controller="controller"
      placeholder="请输入创建人搜索"
      :conditions="conditions"
      :pageSize="20"
    >
      <div slot="list">
        <eagle-cell
          style="margin-top: 10px"
          class="br-8"
          v-for="(item, index) in list"
          :key="index"
        >
          <div v-if="VUE_APP_PLANTFORM=='CY'" @click="goDetail(item.CTCode)">
            <div>
              <eagle-row gutter="15">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_equ_supplier.png"
                  />点检人：{{ item.EditChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                  />点检日期：{{ getDateTime(item.CheckDay) }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />点检结果：
                <span :style="{color:getTextColor(item.CheckResult)}">{{ item.CheckResult }}</span>
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />点检状态：
                <span >{{ getCheckState(item.CheckState) }}</span>
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                  />下次点检日期：{{ getDateTime(item.NextCheckDay) }}
                </eagle-col>
              </eagle-row>
              <eagle-button
                v-if="type==1"
                class="ml-10 mb-10"
                style="float: right; height: 30px"
                size="small"
                type="default"
                @click.stop="goSiteCheck(item)"
                >{{item.CheckState==1?'详情':'点检'}}
              </eagle-button>
            </div>
          </div>
          <div v-else @click="goDetail(item.CTCode)">
            <div>
              <eagle-row gutter="15">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_equ_supplier.png"
                  />点检人：{{ item.EditChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                  />点检日期：{{ getDateTime(item.EditDate) }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />点检结果：
                <span :style="{color:getTextColor(item.CheckResult)}">{{ item.CheckResult }}</span>
            
                </eagle-col>
              </eagle-row>
            </div>
          </div>
        </eagle-cell>
      </div>
    </eagle-page-list>
  </div>
</template>
<script>
import { GetDetail,GetAbnormal } from "@/api/siteFireEquipment";
import { getDateTime } from "@/utils/getDate";
import store from "@/store/index";
export default {
  data() {
    return {
      list: [],
      conditions: {},
      controller: "/SiteCheckTask",
      queryParams: {
        dataType: "His",
        objCode: this.$route.query.objCode,
        keywords: "",
      },
      VUE_APP_PLANTFORM:process.env.VUE_APP_PLANTFORM,
      form: {},
      type:this.$route.query.type,
    };
  },
  created(){
  
    if(process.env.VUE_APP_PLANTFORM&&process.env.VUE_APP_PLANTFORM=="CY"){
      if(this.type==1){
        store.state.title="专项清单点检"  
      }else{
        store.state.title="专项清单点检历史"
      }
      
    }

  },
  methods: {
    bindData(data) {
      this.list = [];
      if (data) {
        data.forEach((item) => {
          if (item.CheckResult == "Y" || item.CheckResult == "NA") {
            item.CheckResult = "正常";
          } else if (item.CheckResult == "N") {
            item.CheckResult = "异常";
          }
        });
        this.list = data;
      }
    },
    getDateTime(value) {
      return getDateTime(value);
    },
    // 详情
    goDetail(CTCode) {
      this.$router.push({
        path: "/SiteFireEquipmentCheck",
        query: { ctCode: CTCode,objCode:this.queryParams.objCode },
      });
    },
    getTextColor(CheckResult){
      console.log(CheckResult)
      if(CheckResult=='异常'){
        return 'red'
      }
      return 'black'
    },
    getCheckState(CheckState){
      if(CheckState==1){
        return '按时'
      }
      return '未点检'
    },
    goSiteCheck(item){
      if(item.CheckState==1){
        this.goDetail(item.CTCode)
      }else{
        let params = { code: item.ObjCode };
      GetDetail(params).then((res) => {
        this.form = res.data;
        this.$router.push({
        path: "/SiteFireEquipmentCheck",
        query: {
          mainCode: res.data.MainCode,
          objCode: item.ObjCode,
          id:item.ID
          // name:this.form.TypeName,
        },
      });

      });

      }
      
    }
  },
};
</script>

<style lang="less">
.op_btn {
  display: flex;
  justify-content: flex-end;
  .btn_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}

.siteHis {
  background-color: #e8f1f8;

  .info_search {
    padding: 10px;
    border-radius: 5px !important;

    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}

.chemical_item {
  background-color: #ffffff;
  border-radius: 5px;
  position: relative;
}

.ch_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
}

.ch_row {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
  .ch_col {
    display: flex;
    align-items: center;
  }
}

.dep_btm {
  display: flex;
  justify-content: flex-end;

  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>
